package com.spring.utils.api_v4.pojo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.spring.utils.api_v4.annotation.ExcelColumn;
import com.spring.utils.api_v4.pojo.salary.EmployeeWage;
import com.spring.utils.api_v4.pojo.salary.task.EmployeeSalaryTask;
import com.spring.utils.api_v4.util.IdcardUtils;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.List;

@Entity
@Table(name = "tb_user")
@Getter
@Setter
@ToString
@GenericGenerator(name = "jpa-uuid", strategy = "uuid")
public class UserInfo implements Serializable {
    @Id
    @GeneratedValue(generator = "jpa-uuid")
    @Column(length = 32)
    private String id;
    @Column(nullable = false, length = 32)
    private String name;                    // 姓名
    @Column(unique = true, nullable = false, length = 18)
    private String idCard;                  // 身份证号码
    @Column(unique = true, nullable = false, length = 32)
    private String phone;                   // 电话号码
    @Column(length = 32)
    private String ethic;                   // 民族
    @Column(length = 32)
    private String politic;                 // 政治面貌
    @Column(length = 32, nullable = false)
    private String state = "在岗";                   // 状态

    @ManyToOne
    @JoinColumn(name = "dept_id")
    private DeptInfo depart;                // 所属部门
    @OneToOne(cascade = CascadeType.ALL)
    private Password password;  // 密码
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "userInfo")
    private List<Role> roles;   // 角色
    @OneToOne(cascade = CascadeType.ALL)
    private EmployeeWage wage;  // 工资信息
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "userInfo")
    private List<EmployeeSalaryTask> salaries;  // 工资发放表

    // 教育经历
    @Column(length = 32)
    private String rawEduExp;               // 初始学历
    @Column(length = 32)
    private String topEduExp;               // 最高学历
    private LocalDate graduationTime;       // 毕业时间
    private String graduateSchool;          // 毕业学校
    private String major;                   // 所学专业
    @Column(length = 32)
    private String degree;                  // 学位

    // 职务信息
    @Column(length = 64)
    private String position;                // 岗位职务
    @Column(length = 64, nullable = false)
    private String rawRole = "普通职工";    // 原始身份
    @Column(length = 64)
    private String roleType;                // 人员类别
    @Column(length = 32)
    private String managePosition;          // 管理职务
    private LocalDate manageApTime;         // 管理职务聘任时间
    @Column(length = 32)
    private String techPosition;            // 专业技术职务
    private LocalDate techApTime;           // 专业技术职务聘任时间
    @Column(length = 32)
    private String skillLevel;              // 工勤技能等级
    private LocalDate skillApTime;          // 工勤技能等级聘任时间

    // 其他信息
    private LocalDate joinWorkTime;         // 参加工作时间
    private LocalDate workTime;             // 来校时间
    private String contractPeriod;          // 合同期限
    private LocalDate contractStartTime;    // 合同起始日期
    private LocalDate contractEndTime;      // 合同起始日期

    public int getAge() {
        return IdcardUtils.getAgeByIdCard(idCard);
    }

    public String getSex() {
        return IdcardUtils.getGenderByIdCard(idCard);
    }

    public int getDeptId() {
        return depart.getId();
    }

    public LocalDate[] getContractDate() {
        return new LocalDate[] {contractStartTime, contractEndTime};
    }
}
